type name = string
type age = int
type adress = string
type telephone = int
type contact = (name * age* adress * telephone)
type agenda = contact list 

let rec exist x liste = match liste with
    []     -> false
   |e1::l1 -> if x = e1 then 
                             true
                        else
                             exist x l1 ;;


let rec add_list x liste = match liste with
      []                 -> x::[]
     |e1::l1 when e1 = x -> x :: e1 :: l1
     |e1::l1 -> e1 :: add_list x l1


let rec remove_list x liste = match liste with
    []                -> []
   |e1::l1 when x = e1 -> l1                            
   |e1::l1 -> e1 :: (remove_list x l1 )


let rec map fonction liste = match liste with
    []     -> []
   |e1::l1 -> (fonction e1)::(map fonction l1) ;;

let rec iter fonction liste = match liste with
   []       -> () 
  |e1 :: l1 -> begin 
                     fonction e1;
                     iter fonction l1;
               end;;

let rec for_all fonction liste = match liste with 
    []     -> true
   |e1::l1 -> fonction e1 && (for_all fonction l1) ;;


let lower_case a = if int_of_char a >= 65 && int_of_char a <= 90 then char_of_int (int_of_char a + 32)
                                                                 else a

let upper_case a = if int_of_char a > 96 && int_of_char a < 123 then char_of_int (int_of_char a - 32 ) 
                                                                else a ;;

let string_of_char c = String.make 1 c ;;

let string_apply fonction chaine = 
  let length = (String.length chaine)-1 in
     let rec fonction2 chaine x chaine2 = match x with   
      
      |x when x <= length -> (string_of_char(fonction chaine.[x])^chaine2)^fonction2 chaine (x+1) chaine2
      |length             -> chaine2
  in fonction2 chaine 0 "" ;;


let string_uppercase chaine = string_apply (upper_case) chaine ;;

let string_lowercase chaine = string_apply (lower_case) chaine ;;
